﻿

CREATE PROCEDURE dbo.s_MovePages
	(
		@ApplID int,
		@ImageTypeID_From int,
		@PageNumber_From int,
		@ImageTypeID_To int,
		@PageNumber_To int,
		@PageCount int
	)
AS


BEGIN TRAN

DECLARE @PageID int

IF @PageNumber_From = 0 SET @PageNumber_From = 1

IF @PageCount = -1 SET @PageCount = dbo.PageCount(@ApplID,@ImageTypeID_From)


EXEC sh_Debug_Put 's_MovePages<> PageCount:$0',@PageCount

SET @PageCount = @PageNumber_To + @PageCount

WHILE @PageNumber_To < @PageCount BEGIN
	
	EXEC sh_Debug_Put 's_MovePages<> @PageNumber_To:$0',@PageNumber_To
	
	EXEC @PageID = s_MovePage	@ApplID,@ImageTypeID_From,@PageNumber_From,@ImageTypeID_To,@PageNumber_To

	SET @PageNumber_To = @PageNumber_To + 1

END

COMMIT TRAN

RETURN @PageID

